package liquidfs.data.fs.util;

import java.util.*;

import com.thoughtworks.xstream.annotations.*;

import liquidfs.core.*;
import liquidfs.data.*;
import liquidfs.data.ex.*;
import liquidfs.data.fs.*;

@XStreamAlias("liquid-object-record")
public class LiquidMetadataCache {

   @XStreamAsAttribute()
   private String path;
   
   @XStreamAsAttribute()
   private Boolean directory = null;
   
   private Long size = null;
   private Metadata metadata = null;
   private List<PeerDevice> storageDevices = null;
   
   public LiquidMetadataCache (String path) {
      this.path = path;
   }
   
   public LiquidMetadataCache (String path, long size, Metadata metadata, boolean directory) {
      this.path = path;
      this.size = size;
      this.metadata = metadata;
      this.directory = directory;
   }
   
   public LiquidMetadataCache (LiquidObject object) {
      this (object.getPath(), object.getSize(), object.getMetadata(), object.isDirectory());
   }
   
   public void clear () {
      this.directory = null;
      this.size = null;
      this.metadata = null;
      this.storageDevices = null;
   }

   public Boolean isDirectory() {
      return directory;
   }
   
   public Long getSize() {
      return size;
   }
   
   public Metadata getMetadata () {
      return metadata;
   }

   public String getPath() {
      return this.path;
   }

   public String getName() {
      return this.path.substring(this.path.lastIndexOf('/') + 1);
   }
   
   public List<PeerDevice> getStorageDevices () {
      return this.storageDevices;
   }
   
   public void setStorageDevices (List<PeerDevice> devices) {
      this.storageDevices = devices;
   }

}
